/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.faytechcc.csc251.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 *
 * @author woodsk9710
 */
public class CollectionWindow
        extends Window
{
    private JPanel buttonPanel;
    private ResultsPanel resultsPanel;
    private JButton removeButton;
    private JButton deckButton;
    private final String query = "SELECT * FROM Collection";

    public CollectionWindow()
    {
        resultsPanel = new ResultsPanel(query);
        this.setResultsPanel(resultsPanel);
        
        buttonPanel = new JPanel();
        removeButton = new JButton("Remove from Collection");
        removeButton.addActionListener(new CollectionDeleteListener(resultsPanel, this));
        deckButton = new JButton("Add to Deck");
        buttonPanel.add(removeButton);
        buttonPanel.add(deckButton);
        
        
        
        this.setButtonPanel(buttonPanel);
        
        this.pack();

        this.setVisible(true);


    }
    public class CollectionDeleteListener implements ActionListener {

        private ResultsPanel resultsPanel;
        private CollectionWindow window;

        public CollectionDeleteListener(ResultsPanel rPanel, CollectionWindow window) {
            this.resultsPanel = rPanel;
            this.window = window;
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            int collectionNum = this.resultsPanel.getSelectedCardCollectionNum();
            try {
                this.window.executePreparedStatement(collectionNum);
//                int row = resultsPanel.table.getSelectedRow();
//                ((DefaultTableModel)resultsPanel.table.getModel()).removeRow(row);
            } catch (SQLException ex) {
                Logger.getLogger(CollectionWindow.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
    }
}
